package com.gaff.emp.core.config.extend;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import java.util.ArrayList;
import java.util.List;

@Component
public class EmpInterceptorRegistry implements BeanPostProcessor {

    private List<HandlerInterceptorAdapter> interceptors = new ArrayList<>();

    public List<HandlerInterceptorAdapter> getInterceptors() {
        return interceptors;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof HandlerInterceptorAdapter) {
            interceptors.add((HandlerInterceptorAdapter) bean);
        }
        return bean;
    }

}
